/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.great.ad;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;
import br.ufc.great.ad.DAO.UserDAO;
import br.ufc.great.ad.Model.User;



/**
 *
 * @author great
 */
@Resource
public class LoginController {

    private Result result;
    UserSession userSession;
    Validator validator;

    public LoginController(Result result, UserSession userSession, Validator validator) {
        this.result = result;
        this.userSession = userSession;
        this.validator = validator;
    }

    public void index() {
    }

    

    public void signSucess() {
    }

    @Restricted
    public void loginSucess() {
    }

    public void loginFailed() {
    }

    @Get
    public void addUser() {
    }

    @Post
    public void login(User user) {

        User userBD = new UserDAO().getUser(user);
        userSession.setUser(userBD);
        if (userSession.isLogged()) {

            result.include("user", userBD);
            result.redirectTo("loginSucess");
        }

        if (!userSession.isLogged()) {
            result.redirectTo("loginFailed");
        }
    }
}
